package com.briup.smartcity.service.impl;

import com.briup.smartcity.bean.Comment;
import com.briup.smartcity.exception.ServiceException;
import com.briup.smartcity.mapper.CategoryMapper;
import com.briup.smartcity.mapper.CommentMapper;
import com.briup.smartcity.mapper.extend.CommentExtendMapper;
import com.briup.smartcity.service.ICommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements ICommentService {
    @Autowired
    private CommentMapper mapper;

    @Autowired
    private CommentExtendMapper extendMapper;
    @Override
    public void checkComment(int id, int status) throws ServiceException {
        Comment comment = new Comment();
        comment.setCommentId(Integer.valueOf(id));
        comment.setCommentStatus(Integer.valueOf(status));
        this.mapper.updateByPrimaryKeySelective(comment);
    }
    @Override
    public PageInfo<Comment> pageQuery(int pageNum, int pageSize, String keywords) {
        PageHelper.startPage(pageNum, pageSize);
        List<Comment> list = this.extendMapper.selectAllCommentByKeyword(keywords);
        return new PageInfo(list);
    }
    @Override
    public void deleteById(int id) throws ServiceException {
        this.mapper.deleteByPrimaryKey(Integer.valueOf(id));
    }
    @Override
    public void batchDelete(int[] ids) throws ServiceException {
        for (int id : ids)
            this.mapper.deleteByPrimaryKey(Integer.valueOf(id));
    }
}
